import json

import requests

URL_POST_ORDER = 'http://127.0.0.1:8000/api/order/post/'
URL_GET_ORDER = 'http://127.0.0.1:8000/api/order/'
URL_ADD_CART = 'http://127.0.0.1:8000/api/cart/add/'
URL_UPDATE_CART = 'http://113.209.31.133/api/cart/update/'
URL_GET_CART = 'http://113.209.31.133/api/cart/'

headers = {
    "Content-Type": "application/json",
    "accept": "application/json",
    "Authorization": "Token e9bc057dce256236e9be2290f5a266435395f823"
}


def post_order():
    data = {
        'products': [{
            'spec_id': '1',
            'amount': 1,
        }]
    }
    r = requests.post(URL_POST_ORDER, headers=headers, data=json.dumps(data))
    if r.status_code == 200:
        print(r.text)
    else:
        print(r.status_code)


def get_order():
    r = requests.get(URL_GET_ORDER, headers=headers)
    if r.status_code == 200:
        print(r.text)
    else:
        print(r.status_code)


def add_cart():
    data = {"spec": 2, "amount": 1}
    r = requests.post(URL_ADD_CART, headers=headers, data=json.dumps(data))
    if r.status_code == 200:
        print(r.text)
    else:
        print(r.status_code)


def update_cart():
    data = {"spec":3,"amount":2}

    r = requests.put(URL_UPDATE_CART, headers=headers, data=json.dumps(data))
    if r.status_code == 200:
        print(r.text)
    else:
        print(str(r.status_code) + ": " + r.text)


def get_cart():
    r = requests.get(URL_GET_CART, headers=headers)
    if r.status_code == 200:
        print(r.text)
    else:
        print(str(r.status_code) + ": " + r.text)

if __name__ == '__main__':
    # add_cart()
    add_cart()
